<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <link class="theme" rel="stylesheet" type="text/css" href="./css/color/blue.css" />
    <script type="text/javascript" src="./script/md5.js"></script>



</head>

<body>
  <div class="head">
    <div class="head-s">
      <span>用户列表</span>
      <div class="head-l"><i class="fa fa-caret-left" onclick="api.closeWin()"></i></div>
      <!-- <div class="head-r"><i class="fa fa-user"></i></div> -->
    </div>
  </div>
    <!-- <header class="aui-bar aui-bar-nav header">
        <a class="aui-pull-left">
            <span class="aui-iconfont aui-icon-left" onclick="api.closeWin()"></span>
        </a>
        <div class="aui-title">用户列表</div>
        <a class="aui-pull-right aui-btn">
            <span class="fa fa-user-circle-o"></span>
        </a>
    </header> -->
    <div class="header-d"></div>

    <div id="list">
    </div>

    <!-- 用户列表 -->
    <script type='text/template' id='template'>
        {{~it :value:index}}
        <div class="user">
            <ul class="aui-list aui-list-in">
                <li class="aui-list-item aui-list-item-middle">
                    <div class="aui-list-item-inner aui-list-item-arrow" onclick="changePassword({{=index}})">
                        <div class="aui-list-item-title">{{=value.UserName}}</div>
                    </div>
                </li>
            </ul>
        </div>
        {{~}}
    </script>

</body>
<script type="text/javascript" src="./script/api.js"></script>

</html>


<script>
    function changePassword(n) {
        var data = $api.getStorage('userData');
        api.confirm({
            title: '',
            msg: '确定要重置该用户的密码么？',
            buttons: ['确定', '取消']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                // console.log(data[n].Password);
                data[n].Password = $.md5('123').toUpperCase();
                $api.setStorage('userData', data);
                api.toast({
                    msg: '修改成功！',
                    duration: 2000,
                    location: 'middle'
                });
                setTimeout("api.closeWin()", 800);
            }
        });


    }

    apiready = function() {
        var color = $api.getStorage('color');
        $(".theme").attr("href", color);

        var data = $api.getStorage('userData');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);

    }
</script>
